package com.dq.service.menu.impl;

import com.dq.domain.sys.menu.SysMenu;
import com.dq.domain.sys.role.SysRoleMenu;
import com.dq.domain.sys.user.user.base.SysUser;
import com.dq.service.BaseServices;
import com.dq.service.menu.SysMenuService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @创建人 gewenzhen
 * @创建时间 2019/9/7
 * @描述
 */
@Service
public class SysMenuServiceImpl extends BaseServices implements SysMenuService {
    @Override
    public List<SysMenu> findBySysUserAndStatus(SysUser sysUser, SysMenu.Status status) {
        return dao.find("select * from SysUserRole sur left join SysRoleMenu srm on sur.sysRole=srm.sysRole where " +
                "sur.sysUser=?0 and srm.sysMenu.status=?1 ", new Object[]{sysUser, status});
    }

    @Override
    public void deleteBath(SysMenu sysMenu) {
        sysMenuRepository.delete(sysMenu);
        List<SysRoleMenu> sysRoleMenus = sysRoleMenuRepository.findBySysMenu(sysMenu);
        sysRoleMenuRepository.deleteAll(sysRoleMenus);
    }
}
